<?php
/**
 * Clase que obtiene la ayuda de los controladores
 */


/**
 * HelpFetcher Class
 */
class HelpFetcher 
{
  
  /**
   * ClassName
   */
  private $class;
  
  /**
   * ControllerName (slugged)
   */
  private $controller;

  public function HelpFetcher($controllerFile)
  {
    $this->class = str_replace('.php','',$controllerFile);
    $controller = substr($this->class,0,-10);
    $this->controller = Formatter::upperCamelCaseToSlug($controller);
  }

  /**
   * Muestra la ayuda de todos los metodos de un controller
   */
  public function showHelp()
  {
    $class = new ReflectionClass($this->class);
    $out = CommandLineInterface::getInstance();
    $methods = $class->getMethods();
    foreach($methods as $method)
    {
      if($method->isPublic() && eregi('Action$',$method->name) )
      {
        $action = substr($method->name,0,-6);
        $action = Formatter::camelCaseToSlug($action);
        $comment = $method->getDocComment();
        $comment = eregi_replace("\\*|\\/",'',$comment);
        $out->printSection($this->controller,':'.$action);
        $out->printSection('',trim($comment),'NOTE');
      }
    }
  }

}



